package com.example.springbootwebfluxdemo.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.springbootwebfluxdemo.mapper.HookMapper;
import com.example.springbootwebfluxdemo.pojo.Hook;
import com.example.springbootwebfluxdemo.service.HookService;
import com.example.springbootwebfluxdemo.util.RequestIpUtil;
import com.example.springbootwebfluxdemo.vo.InfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.reactive.DispatcherHandler;
import org.springframework.web.reactive.function.server.ServerRequest;

import java.util.Date;

/**
* @author 78500
* @description 针对表【hook】的数据库操作Service实现
* @createDate 2022-09-13 09:27:30
*/
@Service
public class HookServiceImpl extends ServiceImpl<HookMapper, Hook>
    implements HookService {


    @Override
    @Transactional
    public void saveSubmit(InfoVo vo, ServerRequest request) {
        String userIp = RequestIpUtil.getUserIp(request);
        Hook hook = new Hook();
        hook.setIp(userIp);
        hook.setDepartment(vo.getDepartment());
        hook.setCreatedate(new Date());
        hook.setMobile(vo.getMobile());
        hook.setName(vo.getUserName());
        //拼接地址
        String address=vo.getProvince()+vo.getCity()+vo.getCounty()+vo.getAddress();
        hook.setAddress(address);
        this.save(hook);
    }

    @Override
    public Boolean updateNameById(Integer id, String name) {
        LambdaUpdateWrapper<Hook> wrapper = Wrappers.lambdaUpdate(Hook.class).set(Hook::getName, name).eq(Hook::getId, id);
          return this.update(wrapper);
    }


}




